#ifndef PFS_THREAD_H
#define PFS_THREAD_H
#include <pthread.h>
#include "MsgQueue.h"
#include <event.h>

namespace PFS
{
    class Thread
    {
        public:
            Thread(thread_fun);
            virtual ~Thread();
            virtual void run() = 0;
            pthread_t get_id();
            int join();
            int detach();
            int exit();
            int start();
            virtual void set_task(void* data){}
        protected:
            pthread_t thread_id;
            pthread_attr_t attr;
            thread_fun fun;
    };

    class EventThread : public Thread
    {
        public:
            EventThread(thread_fun _thread_fun);
            ~EventThread();
            static void* event_thread_start(void* arg);
            virtual void run();
            void set_task(const JobArg& data);
            struct event_base* get_event_base();
        private:
            MsgQueue* m_queue;
            struct event_base *base;
    };

    struct event_arg
    {
        Job* job;
        EventConnection* data;
    };
}
#endif
